package gui;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * description: Login
 * 登录页面
 * @author what-is-me
 * @date 2022/1/3 23:40
 */
public class Login extends JPanel {
    JTextField t;
    JPasswordField p;
    JButton login, signin;

    public Login() {
        /**
         * Description: Login
         * @param :
         * @return {@link null}
         * @throws
         * @author what-is-me
         * @date 2022/1/3 23:32
         */
        setLayout(new BorderLayout());
        t = new JTextField(20);
        p = new JPasswordField(20);
        login = new JButton("登入");
        signin = new JButton("注册");
        add(new GridBagPanel().add(new JLabel("用户名："), 0, 0, 1, 1, 0, 5).add(new JLabel("密码："), 0, 1, 1, 1, 0, 5)
                .add(t, 1, 0, 2, 1, 0, 5).add(p, 1, 1, 2, 1, 0, 5), BorderLayout.CENTER);
        login.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Message.msg = "login";
                Message.args = get();
            }
        });
        signin.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Message.msg = "signin";
                Message.args = get();
            }
        });
        add(new GridBagPanel().add(login, 0, 0, 1, 1, 0, 5).add(signin, 1, 0, 1, 1, 0, 5), BorderLayout.SOUTH);
    }

    String[] get() {
        /**
         * Description: get
         * 获取输入
         * @param :
         * @return {@link java.lang.String[]}
         * @throws
         * @author what-is-me
         * @date 2022/1/3 23:32
         */
        String[] ret = { t.getText(), new String(p.getPassword()) };
        return ret;
    }
}